package com.rzico.sbl.ui.statistic

import androidx.lifecycle.MutableLiveData
import com.lzg.extend.BaseResponse
import com.lzg.extend.JsonConvert
import com.lzg.okrx.adapter.FlowableBody
import com.lzy.okgo.OkGo
import com.lzy.okgo.model.HttpMethod
import com.rzico.sbl.R
import com.rzico.sbl.model.BaseUrl
import com.rzico.sbl.model.ManagerContent
import com.rzico.sbl.model.PayTotalData
import com.rzico.sbl.model.ResponseModel
import com.rzico.sbl.viewmodel.DialogViewModel
import com.xinnuo.common_ui.utils.applyFlowableSchedulers

class StatisticViewModel : DialogViewModel() {

    // 管理员、店长
    fun commonIcons() = arrayListOf(
        ManagerContent("押桶", R.mipmap.icon_statistic09),
        ManagerContent("空桶", R.mipmap.icon_statistic01),
        ManagerContent("推广", R.mipmap.icon_statistic02),
        ManagerContent("记账", R.mipmap.icon_statistic03),
        ManagerContent("送货", R.mipmap.icon_statistic04),
        ManagerContent("水票", R.mipmap.icon_statistic05),
        ManagerContent("商品", R.mipmap.icon_statistic08),
        ManagerContent("配送联盟", R.mipmap.icon_union01),
        ManagerContent("库存管理", R.mipmap.icon_stock01)
    )

    val mTitleList = arrayListOf("收款", "订单")

    val mOrderEvent = MutableLiveData("{}")

    /**
     * 今日收款数
     */
    fun getPaySum(
        beginDate: String,
        endDate: String
    ) =
        OkGo.get<BaseResponse<ResponseModel<PayTotalData>>>(BaseUrl.stsPaySum)
            .params(
                getParams(
                    "beginDate" to beginDate,
                    "endDate" to endDate
                )
            )
            .converter(object : JsonConvert<BaseResponse<ResponseModel<PayTotalData>>>() {})
            .adapt(FlowableBody())
            .compose(applyFlowableSchedulers())
            .map { it.data.data }

    /**
     * 今日订单数
     */
    fun getOrderSum(
        beginDate: String,
        endDate: String
    ) =
        request(
            isLoadingBefore = false,
            isLoadingAfter = false,
            requestUrl = BaseUrl.stsOrderSum,
            requestMethod = HttpMethod.GET,
            params = arrayOf(
                "beginDate" to beginDate,
                "endDate" to endDate
            ),
            onSuccess = { mOrderEvent.value = it }
        )

}